Fix slice filter appending fill_with when items divide evenly#2150
Closed
Krishnachaitanyakc wants to merge 2 commits intopallets:mainfrom
Closed
Fix slice filter appending fill_with when items divide evenly#2150Krishnachaitanyakc wants to merge 2 commits intopallets:mainfrom
Krishnachaitanyakc wants to merge 2 commits intopallets:mainfrom
Conversation
When the iterable length is evenly divisible by the slice count, `slices_with_extra` is 0. The condition `slice_number >= slices_with_extra` is then always true, causing `fill_with` to be incorrectly appended to every slice. Add a truthiness check for `slices_with_extra` to ensure `fill_with` is only appended when there are actually shorter slices that need padding. Fixes pallets#2118
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slicefilter incorrectly appendingfill_withto every slice when the iterable length is evenly divisible by the slice count.length % slices == 0,slices_with_extrais0, making the conditionslice_number >= slices_with_extraalwaysTrue. This causesfill_withto be appended to every slice even though no padding is needed.slices_with_extrabefore the comparison, sofill_withis only appended when there are actually shorter slices that need padding.Before (broken):
After (fixed):
Fixes #2118
Test plan
test_slice_evenly_divisiblecovering evenly divisible cases (4 items / 4 slices, 6 items / 2 slices)test_slicestill passes (non-evenly-divisible case with fill_with works correctly)